find all possible paths in a matrix